package com.guigu.pd.work.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.common.utils.PageVo;
import com.guigu.pd.serviceapi.pojo.AddShuJuDTO;
import com.guigu.pd.serviceapi.pojo.DriverJob;
import com.guigu.pd.serviceapi.pojo.TaskTransport;
import com.guigu.pd.serviceapi.pojo.TransportOrderTask;
import com.guigu.pd.work.entity.DriverJobEntity;
import com.guigu.pd.work.entity.TransportOrderTaskEntity;
import com.guigu.pd.work.service.DriverJobService;
import com.guigu.pd.work.service.TransportOrderTaskService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guigu.pd.work.entity.TaskTransportEntity;
import com.guigu.pd.work.service.TaskTransportService;
import com.guigu.common.utils.PageUtils;
import com.guigu.common.utils.R;



/**
 * 运输任务表
 *
 * @author deyran
 * @email deyran@gmail.com
 * @date 2022-07-19 19:31:34
 */
@RestController
@RequestMapping("work/tasktransport")
public class TaskTransportController {

    @Autowired
    private TransportOrderTaskService transportOrderTaskService;
    @Autowired
    private TaskTransportService taskTransportService;
    @Autowired
    private DriverJobService driverJobService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageVo<TaskTransportEntity> page = taskTransportService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		TaskTransportEntity taskTransport = taskTransportService.getinfoById(id);

        return R.ok().put("taskTransport", taskTransport).put("transportorder",taskTransport.getTransportOrder());
    }

    /**
     * 信息
     */
    @GetMapping("/gettruckstatus")
    public R gettruckstatusinfo(){
        QueryWrapper<TaskTransportEntity> queryWrapper = new QueryWrapper<TaskTransportEntity>();
        queryWrapper.eq("loading_status",1);
        List<TaskTransportEntity> list1 = taskTransportService.list(queryWrapper);

        QueryWrapper<TaskTransportEntity> queryWrapper2 = new QueryWrapper<TaskTransportEntity>();
        queryWrapper2.eq("loading_status",2);
        List<TaskTransportEntity> list2 = taskTransportService.list(queryWrapper2);

        QueryWrapper<TaskTransportEntity> queryWrapper3 = new QueryWrapper<TaskTransportEntity>();
        queryWrapper3.eq("loading_status",3);
        List<TaskTransportEntity> list3 = taskTransportService.list(queryWrapper3);

        return R.ok().put("fullsum", list1.size()).put("halfsum",list2.size()).put("emptysum",list3.size());
    }

    //批量添加数据
    @PostMapping("/piliangadd")
    public boolean piliangadd(@RequestBody AddShuJuDTO addShuJuDTO){

        List<TransportOrderTaskEntity> list1 = new ArrayList<>();
        BeanUtils.copyProperties(list1,addShuJuDTO.getTransportOrderTaskslist());
        List<TaskTransportEntity> list2 = new ArrayList<>();
        BeanUtils.copyProperties(list2,addShuJuDTO.getTaskTransportList());
        List<DriverJobEntity> list3 = new ArrayList<>();
        BeanUtils.copyProperties(list3,addShuJuDTO.getDriverJobList());

        transportOrderTaskService.saveBatch(list1);
        taskTransportService.saveBatch(list2);
        boolean b = driverJobService.saveBatch(list3);

        return b;

    }

}
